﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using DH.Web.Controllers;
using DH.Core;
using DH.Core.UI.ViewModel;
using Microsoft.Extensions.DependencyInjection;
using DH.Service;

namespace DH.Web.MVC.Controllers
{
    public class SiteController<TCodeTabelEntity, TCodeTabelModel,Tkey> : CrudControllerBase<TCodeTabelEntity, TCodeTabelModel, Tkey> 
        where TCodeTabelEntity : BaseEntity<Tkey>, new()
        where TCodeTabelModel : EntityModelBase<Tkey>, new()
    {
        protected IServiceCollection _service;
        protected SiteController(IServiceCollection serviceCollection,
                                 BaseService<TCodeTabelEntity, Tkey> baseService
                                 ) : base(serviceCollection, baseService)
        {
            _service = serviceCollection;
        }

        UserSessionEx _userSessionEx;
        public UserSessionEx CurrentUserEx {
            get {
                if (_userSessionEx!=null)
                {
                    return _userSessionEx;
                }
                else
                {
                    var userSessionEx = new UserSessionEx(_service);
                    userSessionEx.DepartmentId = CurrentUser.DepartmentId;
                    userSessionEx.IsAdmin = CurrentUser.IsAdmin;
                    userSessionEx.IsDeveloper = CurrentUser.IsDeveloper;
                    userSessionEx.LoginIP = CurrentUser.LoginIP;
                    userSessionEx.LoginTime = CurrentUser.LoginTime;
                    userSessionEx.RealName = CurrentUser.RealName;
                    userSessionEx.RoleId = CurrentUser.RoleId;
                    userSessionEx.UserId = CurrentUser.UserId;
                    userSessionEx.DepartmentId = CurrentUser.DepartmentId;
                    userSessionEx.UserName = CurrentUser.UserName;
                    
                    _userSessionEx = userSessionEx;
                    return _userSessionEx;
                }
            }
            set {
                _userSessionEx = value;
            }
        }
    }
}